export default defineEventHandler(async (event) => {
  // 模拟用户数据
  const users = [
    {
      id: 1,
      name: '张三',
      email: 'zhangsan@example.com',
      avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=1',
      role: 'admin',
      status: 'active',
      createdAt: '2024-01-15T10:30:00Z'
    },
    {
      id: 2,
      name: '李四',
      email: 'lisi@example.com',
      avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=2',
      role: 'user',
      status: 'active',
      createdAt: '2024-01-20T14:20:00Z'
    },
    {
      id: 3,
      name: '王五',
      email: 'wangwu@example.com',
      avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=3',
      role: 'user',
      status: 'inactive',
      createdAt: '2024-02-01T09:15:00Z'
    },
    {
      id: 4,
      name: '赵六',
      email: 'zhaoliu@example.com',
      avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=4',
      role: 'moderator',
      status: 'active',
      createdAt: '2024-02-10T16:45:00Z'
    },
    {
      id: 5,
      name: '钱七',
      email: 'qianqi@example.com',
      avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=5',
      role: 'user',
      status: 'active',
      createdAt: '2024-02-15T11:30:00Z'
    }
  ]

  // 获取查询参数
  const query = getQuery(event)
  const page = parseInt(query.page as string) || 1
  const limit = parseInt(query.limit as string) || 10
  const search = query.search as string

  // 过滤数据
  let filteredUsers = users
  if (search) {
    filteredUsers = users.filter(user => 
      user.name.toLowerCase().includes(search.toLowerCase()) ||
      user.email.toLowerCase().includes(search.toLowerCase())
    )
  }

  // 分页
  const startIndex = (page - 1) * limit
  const endIndex = startIndex + limit
  const paginatedUsers = filteredUsers.slice(startIndex, endIndex)

  // 模拟延迟
  await new Promise(resolve => setTimeout(resolve, 200))

  return {
    code: 200,
    message: '获取用户列表成功',
    data: {
      users: paginatedUsers,
      pagination: {
        page,
        limit,
        total: filteredUsers.length,
        totalPages: Math.ceil(filteredUsers.length / limit)
      }
    }
  }
}) 